import 'package:flutter/material.dart';

class MissionPage extends StatefulWidget {
  const MissionPage({Key? key, this.animationController}) : super(key: key);

  final AnimationController? animationController;
  @override
  _MissionPageState createState() => _MissionPageState();
}

class _MissionPageState extends State<MissionPage> with TickerProviderStateMixin {
  Animation<double>? topBarAnimation;

  List<Widget> listViews = <Widget>[];
  final ScrollController scrollController = ScrollController();
  double topBarOpacity = 0.0;
  List<MissionItemData> missionItems = [
    MissionItemData(icon: Icons.thumb_up, text: '点赞量', value: '100'),
    MissionItemData(icon: Icons.bookmark, text: '收藏量', value: '50'),
    MissionItemData(icon: Icons.comment, text: '评论量', value: '20'),
    MissionItemData(icon: Icons.person_add, text: '粉丝数', value: '500'),
  ];
  List<String> tasks = [
    '任务1',
    '任务2',
    '任务3',
    '任务4',
  ];
  List<bool> taskValues = [false, false, false, false];
  String imageUrl = 'lib/images/grow1.png'; // 初始图像URL
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: null,
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              SizedBox(height: 20,),
              const Text(
                '今日任务',
                style: TextStyle(
                    fontSize: 24.0, fontWeight: FontWeight.bold),
              ),
              Container(
                width: 500,
                margin: EdgeInsets.only(bottom: 10),
                height: 300,
                child: ListView.builder(
                  padding: EdgeInsets.all(10),
                  itemBuilder: (BuildContext context, int index) {
                    return Container(
                      margin: EdgeInsets.only(bottom: 10),
                      height: 290,
                      child: Row(
                        children: <Widget>[

                          SizedBox(width: 16),
                          Expanded(
                            child: ListView.builder(
                              scrollDirection: Axis.horizontal,
                              itemBuilder: (BuildContext context, int index) {
                                return Row(
                                  children: [
                                    TaskCard(
                                      taskName: '发布高质量内容',
                                      taskDescription: '内容要求：新颖、有创意、有深度，能够吸引粉丝的注意和互动',
                                      taskTime: '时间安排：今天至少发布\n一篇以上高质量的穿搭帖\n子或视频',
                                      imagePath: 'lib/images/helpImage.png',
                                    ),
                                    SizedBox(width: 16),
                                    TaskCard(
                                      taskName: '与粉丝互动',
                                      taskDescription: '内容要求：真诚、友善、贴近粉丝，建立良好的互动关系，提升粉丝忠诚度',
                                      taskTime: '时间安排：每三个小时查看回复粉丝评论、私信，参与粉丝的讨论和互动',
                                      imagePath: 'lib/images/feedbackImage.png',
                                    ),
                                    SizedBox(width: 16),
                                    TaskCard(
                                      taskName: '投流',
                                      taskDescription: '内容要求：投流50元，选择第一条笔记，选择评论提升量为投流目标',
                                      taskTime: '时间安排：今天在薯条聚光平台上进行投流\n试水',
                                      imagePath: 'lib/images/inviteImage.png',
                                    ),
                                  ],
                                );
                              },
                              itemCount: 1,
                            ),
                          ),
                        ],
                      ),
                    );
                  },
                  itemCount: 1,
                ),
              ),
              Text(
                '今日总结',
                style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
              ),
              Padding(
                padding: EdgeInsets.all(16.0),
                child: Container(
                  padding: EdgeInsets.all(10.0),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10.0),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.grey.withOpacity(0.5),
                        spreadRadius: 3,
                        blurRadius: 5,
                        offset: Offset(0, 3), // changes position of shadow
                      ),
                    ],
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        '本月连续完成任务天数',
                        style: TextStyle(
                            fontSize: 15.0, fontWeight: FontWeight.bold),
                      ),
                      Image.asset(
                        'lib/images/continue.png', // 使用动态的图像URL
                        width: 400,
                        height: 290,
                      ),
                      Text(
                        '连续完成：7天                 最高连续记录：18天',
                        style: TextStyle(fontSize: 15.0,
                            fontWeight: FontWeight.bold,
                            color: Colors.grey),
                      ),
                    ],
                  ),
                ),
              ),
              Text(
                '今日成长',
                style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
              ),
              SizedBox(height: 20.0),
              Padding(
                padding: EdgeInsets.all(16.0),
                child: Container(
                  padding: EdgeInsets.all(10.0),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10.0),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.grey.withOpacity(0.5),
                        spreadRadius: 3,
                        blurRadius: 5,
                        offset: Offset(0, 3), // changes position of shadow
                      ),
                    ],
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      GestureDetector(
                        onTap: () {
                          // 在这里执行更改图像URL的操作
                          setState(() {
                            imageUrl = 'lib/images/grow2.png'; // 替换为您的新图片URL
                          });
                        },
                        child: Image.asset(
                          imageUrl, // 使用动态的图像URL
                          width: 400,
                          height: 260,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              Padding(
                padding: EdgeInsets.all(16.0),
                child: Container(
                  padding: EdgeInsets.all(10.0),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10.0),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.grey.withOpacity(0.5),
                        spreadRadius: 3,
                        blurRadius: 5,
                        offset: Offset(0, 3), // changes position of shadow
                      ),
                    ],
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Image.asset(
                        'lib/images/grow3.png', // 使用动态的图像URL
                        width: 400,
                        height: 200,
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

}




class MissionItemData {
  final IconData icon;
  final String text;
  final String value; // 添加 value 参数

  MissionItemData({required this.icon, required this.text, this.value=''});
}


class MissionItem extends StatelessWidget {
  final IconData icon;
  final String text;
  final String value;

  const MissionItem({Key? key, required this.icon, required this.text, required this.value})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Icon(icon, color: Colors.blue),
        SizedBox(width: 8.0),
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              text,
              style: TextStyle(fontSize: 14.0, color: Colors.grey), // 将文本变成灰色并变小
            ),
            Text(
              value,
              style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold), // 将数字文本变大
            ),
          ],
        ),
      ],
    );
  }
}

class TaskCard extends StatelessWidget {
  final String taskName;
  final String taskDescription;
  final String taskTime;
  final String imagePath;

  TaskCard({
    required this.taskName,
    required this.taskDescription,
    required this.taskTime,
    required this.imagePath,
  });

  @override
  Widget build(BuildContext context) {
    return Card(
      margin: EdgeInsets.symmetric(vertical: 10.0),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(20.0),
      ),
      elevation: 5,
      child: Container(
        width: 200,
        padding: EdgeInsets.fromLTRB(16.0, 16.0, 6.0, 0.0),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(20.0),
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [
              Color(0xFF51CCBB),
              Color(0xFF51CCBB).withOpacity(0.3),
            ],
          ),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              taskName,
              style: TextStyle(
                color: Colors.white,
                fontSize: 18.0,
                fontWeight: FontWeight.bold,
              ),
            ),
            SizedBox(height: 8.0),
            Text(
              taskDescription,
              style: TextStyle(color: Colors.white, fontSize: 15.0,),
            ),
            SizedBox(height: 8.0),
            Text(
              taskTime,
              style: TextStyle(color: Colors.white, fontSize: 15.0,),
            ),
            Expanded(
              child: Align(
                alignment: Alignment.bottomRight,
                child: Image.asset(
                  imagePath,
                  fit: BoxFit.fill, // 或者使用 BoxFit.fill
                    width: 90, // 设置宽度为原始尺寸的倍数
                    height: 130,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
